package com.admin.socketmultiplayer.dialog

import android.content.Context
import android.widget.Toast
import com.admin.socketmultiplayer.activity.MyApplication
import com.admin.socketmultiplayer.config.DataUtils
import com.admin.socketmultiplayer.config.FixedValue
import com.admin.socketmultiplayer.config.FixedValue.CONNECTION_IP
import kotlinx.android.synthetic.main.dialog_changer_server_ip.*
import kotlinx.android.synthetic.main.dialog_changer_server_ip.view.*

/**
 * Created by 吴昶 on 2018/4/27.
 */
class ChangerServerIp(context: Context,layout:Int,theme:Int):BaseDialog(context,layout,theme){


    override fun initData() {
        var ip=MyApplication.getSharedPreferencesString(FixedValue.SERVER_IP,CONNECTION_IP)
        fview.edt_server_ip.setText(ip)

        btn_save_ip.setOnClickListener {
            var newIp=fview.edt_server_ip.text.toString()
            if(newIp==null||newIp==""){
                Toast.makeText(context,"请输入Ip地址",Toast.LENGTH_LONG).show()
            }else if(DataUtils.isPhoneNumRight(newIp,FixedValue.IP)){
                Toast.makeText(context,"Ip地址格式错误",Toast.LENGTH_LONG).show()
            }else{
                MyApplication.setSharedPreferencesString(FixedValue.SERVER_IP,newIp)
                this.cancel()
            }
        }
    }

}